﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Com.CMS263.PO;
using NHibernate;

namespace Com.CMS263.DAO
{
    public class ProdTypeDAO : BaseService 
    {

        #region 查询所有list
        /// <summary>
        /// 查询所有list
        /// </summary>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public IList<ProdType> GetAll(int page, int pagesize,string key)
        {
            string hql ="from ProdType where 1=1 ";
            if (!String.IsNullOrEmpty(key))
            {
                hql += " and TypeName like '%" + key + "%'";
            }
            try
            {
                return FindList<ProdType>(hql, null, (page - 1) * pagesize, pagesize);
                
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region 查询所有总数
        /// <summary>
        /// 查询所有总数
        /// </summary>
        /// <returns></returns>
        public int GetAll(string key)
        {
            string hql = "select count(*) from ProdType where 1=1 ";
            if (!String.IsNullOrEmpty(key))
            {
                hql += " and TypeName like '%" + key + "%'";
            }
            try
            {
                
                return Convert.ToInt32(GetValue(hql));
            }
            catch
            {
                return 0;
            }
        }
        #endregion

        public IList<ProdType> FindAll()
        {
            string hql = "from ProdType where IsUse='true'";
            return FindList<ProdType>(hql, null, null, null);
        }
        #region 根据id查询实体
        /// <summary>
        /// 根据id查询实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ProdType GetProdTypeById(int id)
        {
            try
            {
                string hql = "from ProdType where Id=" + id;
                return DBHelper.ExecuteHQL(hql).List<ProdType>().First();
            }
            catch
            {
                return null;
            }
        }
        #endregion
    }
}
